import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    port: 5173,
    proxy: {
      '/user': {
        target: 'http://localhost:8023', // 后端服务器地址
        changeOrigin: true
      },
      '/api/student': {
        target: 'http://localhost:8025', // 后端学生管理服务地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/student/, '/student')
      },
      '/api/class': {
        target: 'http://localhost:8025', // 后端班级管理服务地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/class/, '/class')
      },
      '/api/attendance': {
        target: 'http://localhost:8026', // 后端学生考勤服务地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/attendance/, '/student-attendance-service')
      },
      '/api/safety': {
        target: 'http://localhost:8001', // 后端学生考勤服务地址
        changeOrigin: true
      },
      '/api/guard': {
        target: 'http://localhost:8001', // 后端学生考勤服务地址
        changeOrigin: true
      },
      '/api/patrol': {
        target: 'http://localhost:8001', // 后端学生考勤服务地址
        changeOrigin: true
      },
      '/api/security-guard-user': {
        target: 'http://localhost:8001', // 后端学生考勤服务地址
        changeOrigin: true
      },
      '/api/staff': {
        target: 'http://localhost:9071',
        changeOrigin: true
      },
      '/inspection': {
        target: 'http://localhost:8081', // 后端服务器地址
        changeOrigin: true
      },
      '/api/exams': {
        target: 'http://localhost:7010',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api\/exams/, '/exams')
      },
      '/api': {
        target: 'http://localhost:9527',
        changeOrigin: true,
        rewrite: (path) => path
      },
    }
  }
})
